package com.ljf.game.event;

import com.ljf.game.WebsocketManager;
import com.ljf.game.schedule.HeartBeatSchedule;
import org.springframework.web.socket.WebSocketSession;

import java.util.HashMap;

/**
 * 描述 :
 *
 {
 "EVENT_CLASS":"CREATE_ROOM"
 }
 * <p>
 * 版本     作者     时间      内容
 * 1.0      lijinfeng       2025-04-29 14:32     create
 */
public class CreateRoomEvent extends AbstractEvent {


    public void run(WebSocketSession session,String text) {

        HashMap<String, Object> hashMap = EventManager.getResultMap(text);

        String username = WebsocketManager.getUsername(session);
        // 先添加心跳记录再创建房间，不然在创建完房间的空隙会检测到没有心跳
        HeartBeatSchedule.addExistSession(username);
        // 创建房间
        WebsocketManager.createGroup(username,session);
        WebsocketManager.sendMessage(session, hashMap, "创建房间成功：房主："+username);
    }
}
